# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2023年03月14日
"""
import openpyxl

myBook = openpyxl.load_workbook('收入表.xlsx')
mySheet = myBook.active
# 根据起始单元格和结束单元格设置数据范围的最小行数和最大行数
myMinRow = mySheet.min_row + 4
myMinCol = mySheet.min_column + 1
myMaxRow = mySheet.max_row
myMaxCol = mySheet.max_column
# 指定按列操作单元格的数据范围

myRange = mySheet.iter_cols(min_row=myMinRow, min_col=myMinCol, max_row=myMaxRow, max_col=myMaxCol)
print(myRange)
myRowIndex = myMinRow + 4
myColIndex = myMinCol - 1
mySheet.cell(myRowIndex, myColIndex).value = '合计'
# 按列对单元格进行数据求和
for myCol in myRange:
	myColIndex += 1
	myColSum = sum(myCell.value for myCell in myCol)
	mySheet.cell(myRowIndex, myColIndex).value = myColSum

myBook.save('收入表.xlsx')
